package po;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Calendar;

import database.auxiliary.LogGenerator;

public class OrderPO implements Serializable {

	private static final long serialVersionUID = 8948846261231587831L;

	private int id;
	private String orderNumber;
	private Calendar time;
	private int memberID;
	private ArrayList<SaleItemPO> items;
	private int giftID;
	private String address;
	private double originalPrice;
	private double realPay;
	private OrderState state;

	public OrderPO(int id, String orderNumber, Calendar time, int memberID,
			ArrayList<SaleItemPO> items, int giftID, String address,
			double originalPrice, double realPay, OrderState state) {
		super();
		this.id = id;
		this.orderNumber = orderNumber;
		this.time = time;
		this.memberID = memberID;
		this.items = items;
		this.giftID = giftID;
		this.address = address;
		this.originalPrice = originalPrice;
		this.realPay = realPay;
		this.state = state;
	}

	public OrderPO() {
		super();
		this.id = 0;
		this.orderNumber = "";
		this.memberID = 0;
		this.items = new ArrayList<SaleItemPO>();
		this.giftID = 0;
		this.address = "";
		this.originalPrice = 0;
		this.realPay = 0;
		this.state = OrderState.PLACED;
	}

	public OrderPO(OrderPO orderPO) {
		this.id = orderPO.id;
		this.orderNumber = orderPO.orderNumber;
		this.time = (Calendar) orderPO.time.clone();
		this.memberID = orderPO.memberID;
		ArrayList<SaleItemPO> its = new ArrayList<SaleItemPO>();
		for (int i = 0; i < orderPO.items.size(); i++) {
			its.add(new SaleItemPO(orderPO.items.get(i)));
		}
		this.items = its;
		this.giftID = orderPO.giftID;
		this.address = orderPO.address;
		this.originalPrice = orderPO.originalPrice;
		this.realPay = orderPO.realPay;
		this.state = orderPO.state;
	}

	@Override
	public String toString() {
		return "OrderPO [id=" + id + ", orderNumber=" + orderNumber + ", time="
				+ LogGenerator.calendarToString(time) + ", memberID="
				+ memberID + ", items=" + items + ", giftID=" + giftID
				+ ", address=" + address + ", originalPrice=" + originalPrice
				+ ", realPay=" + realPay + ", state=" + state + "]";
	}

	public OrderState getState() {
		return state;
	}

	public void setState(OrderState state) {
		this.state = state;
	}

	public int getId() {
		return id;
	}

	public String getOrderNumber() {
		return orderNumber;
	}

	public Calendar getTime() {
		return time;
	}
	
	public String getTimeString() {
		return LogGenerator.calendarToString(time);
	}

	public int getMemberID() {
		return memberID;
	}

	public ArrayList<SaleItemPO> getItems() {
		return items;
	}

	public int getGiftID() {
		return giftID;
	}

	public String getAddress() {
		return address;
	}

	public double getOriginalPrice() {
		return originalPrice;
	}

	public double getRealPay() {
		return realPay;
	}

	public void setId(int id) {
		this.id = id;
	}

	public void setOrderNumber(String orderNumber) {
		this.orderNumber = orderNumber;
	}

	public void setTime(Calendar time) {
		this.time = time;
	}

	public void setMemberID(int memberID) {
		this.memberID = memberID;
	}

	public void setItems(ArrayList<SaleItemPO> items) {
		this.items = items;
	}

	public void setGiftID(int giftID) {
		this.giftID = giftID;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public void setOriginalPrice(double originalPrice) {
		this.originalPrice = originalPrice;
	}

	public void setRealPay(double realPay) {
		this.realPay = realPay;
	}

}
